package com.rongxue.utils;


import java.util.ArrayList;
import java.util.List;

public class Page<T>{

    private Integer p;//当前页

    private double pageSize;//每页长度

    private Integer recordTotal;//总记录数

    private Integer pageTotal;//总页数

    private List<T> content;//被分页的list

    /**
     * 获取分页
     * @param list 被分页的list
     * @return
     */
    public  List<T> getPageContent(List<T> list){
        this.recordTotal=list.size();
        this.pageTotal =(int)Math.ceil(list.size()/this.pageSize);
        if(this.pageTotal<1) this.pageTotal=1;
        List<T> content = new ArrayList<T>();
        for (int i =0;i<list.size();i++){
            if(i>=(this.p-1)*this.pageSize){
                content.add(list.get(i));
                if (content.size()==this.pageSize){
                    break;
                }
            }
        }
        return content;
    }

    public Integer getP() {
        return p;
    }

    public void setP(Integer p) {
        this.p = p;
    }

    public double getPageSize() {
        return pageSize;
    }

    public void setPageSize(double pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageTotal() {
        return pageTotal;
    }

    public Integer getRecordTotal() {
        return recordTotal;
    }

    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
    }
}